package com.ce.pms.system.custservice.service;

import java.util.List;

import org.hibernate.exception.ConstraintViolationException;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.dao.DataIntegrityViolationException;

import com.ce.pms.DBUnitTool;
import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.system.custservice.dao.IEmergencyDegreeDao;
import com.ce.pms.system.custservice.model.EmergencyDegreeDO;
import com.ce.pms.system.custservice.vo.EmergencyDegreeVO;
/**
 * 功能描述: 紧急程度维护服务Service单元测试类
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author  胡煦
 * Create on:2008-12-19
 * Edit author:
 * Edit on:
 * 修改原因：

 */

public class EmergencyDegreeServiceImplT extends DBUnitTool {
	/**
	 * 方法描述: 紧急程度列表查询test方法
	 * @author 胡煦
	 * Create on:2008-12-16
	 * @param name
	 * @return List<SignReadingRuleVO>
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	@Test
	public void testQueryAllEmergencyDegreeByPage() {
		SearchVO searchVO = new SearchVO("name desc",1, 5);
		List list = emergencyDegreeService.queryAllEmergencyDegreeByPage(searchVO).getResult();
		Assert.assertNotNull("断言不为空",list);
	}
	/**
	 * 方法描述:紧急程度列表查询方法(根据序号升序排序，如果为空则在最后)
	 * @author 胡煦
	 * Create on:2008-12-16
	 * @param name
	 * @return List<SignReadingRuleVO>
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	@Test
	public void testGetEmergencyDegreeList(){
		List list = emergencyDegreeService.getEmergencyDegreeList();
		Assert.assertNotNull("断言不为空",list);
	}
	/**
	 * 方法描述: 紧急程度增加test方法
	 *
	 * @author 胡煦 Create on:2008-12-16
	 * @param SignReadingRuleVO
	 * @return SignReadingRuleVO Edit author: Edit on: 修改原因：
	 */
	@Test
	public void testAddEmergencyDegree() {
		EmergencyDegreeVO emergencyDegreeVO = new EmergencyDegreeVO();
		emergencyDegreeVO.setCreator(1l);
		emergencyDegreeVO.setName("测试二");
		emergencyDegreeVO.setModifier(1l);

		try {
			emergencyDegreeVO = emergencyDegreeService.addEmergencyDegree(emergencyDegreeVO);
			Assert.assertNotNull("断言不为空",emergencyDegreeVO.getKeyword());
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "custservice:system_name_exist_exception");
		}
	}
	/**
	 * 方法描述: 紧急程度删除test方法
	 *
	 * @author 胡煦 Create on:2008-12-16
	 * @param SignReadingRuleVO
	 * @return SignReadingRuleVO Edit author: Edit on: 修改原因：
	 */
	@Test
	public void testDeleteEmergencyDegree() {
		Long emergencyDegreeId = 1l;


		try {
			emergencyDegreeService.deleteEmergencyDegree(emergencyDegreeId);
			EmergencyDegreeDO degreeDO = emergencyDegreeDao.findById(emergencyDegreeId);
			Assert.assertNull("断言为空",degreeDO);

		} catch (ConstraintViolationException e) {
			e.printStackTrace();
			Assert.fail("抛出异常");
		}catch (DataIntegrityViolationException e) {
			e.printStackTrace();
			Assert.fail("抛出异常");
		}
	}
	/**
	 * 方法描述: 紧急程度修改test方法
	 *
	 * @author 胡煦 Create on:2008-12-16
	 * @param readingRuleId
	 * @return boolean Edit author: Edit on: 修改原因：
	 */
	@Test
	public void testEditEmergencyDegree() {
		EmergencyDegreeVO emergencyDegreeVO = new EmergencyDegreeVO();
		emergencyDegreeVO.setKeyword(5l);
		emergencyDegreeVO.setCreator(1l);
		emergencyDegreeVO.setName("测试二");
		emergencyDegreeVO.setModifier(1l);

		try {
			emergencyDegreeVO = emergencyDegreeService.editEmergencyDegree(emergencyDegreeVO);
			Assert.assertEquals("测试二", emergencyDegreeVO.getName());
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "custservice:system_name_exist_exception");
		}
	}
	/**
	 * 功能描述:校验紧急程度名字是否存在test方法<br>
	 * 注：新建判断name的唯一性时，oldId传为null；修改判断name的唯一性时，则需要传入本身的ID<br>
	 * @param name
	 * @param id
	 * @return
	 * Create author:胡煦
	 * Create on:2008-7-18
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	@Test
	public void testCheckEmergencyDegreeByName(){

		try {
			emergencyDegreeService.checkEmergencyDegreeByName("测试二", null);
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "custservice:system_name_exist_exception");
		}
	}
	static private IEmergencyDegreeService emergencyDegreeService;
	static private IEmergencyDegreeDao emergencyDegreeDao;
	/**
    *
    * 功能描述:   <br>
    *
    * Create author：胡煦  <br>
    * Create on:2008-12-17  <br>
    * Edit author：  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
	@BeforeClass
	public static void initEmergencyDegree(){
		if (emergencyDegreeService == null) {
			emergencyDegreeService = (IEmergencyDegreeService)DBUnitTool.applicationContext.getBean("emergencyDegreeService");
		}
		if (emergencyDegreeDao == null) {
			emergencyDegreeDao = (IEmergencyDegreeDao)DBUnitTool.applicationContext.getBean("emergencyDegreeDao");
		}
	}
}
